﻿// --------------------------------
// <copyright file="TableCollectionTest.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tronsoft.Actucal.Tables.Test
{
    
    
    /// <summary>
    ///This is a test class for TableCollectionTest and is intended
    ///to contain all TableCollectionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TableCollectionTest
    {
        private const string TABLE_COLUMN_1 = "Col1";
        private const string TABLE_COLUMN_2 = "Col2";

        readonly DataTable dtTest = new DataTable();

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        public void MyTestInitialize()
        {
            // Define columns
            dtTest.Columns.Add(TABLE_COLUMN_1, typeof(int));
            dtTest.Columns.Add(TABLE_COLUMN_2, typeof(string));

            // Add new rows
            dtTest.Rows.Add(1, "Data1");
            dtTest.Rows.Add(2, "Data2");
        }
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void Should_Be_Able_Tools_Index_Table_By_Name()
        {
            const string TABLE_NAME = "Table1";

            TableCollection target = new TableCollection();
            target.Add(TABLE_NAME);
            TableDefinition actual = target[TABLE_NAME];

            Assert.AreEqual(TABLE_NAME, actual.TableName);
        }

        [TestMethod()]
        public void Should_Return_Null_If_Name_Index_Does_Not_Exists()
        {
            TableCollection target = new TableCollection();
            TableDefinition actual = target["Table That does not exist"];

            Assert.AreEqual(null, actual);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Should_Be_Able_Tools_Index_Table_By_Empty_Name()
        {
            TableCollection target = new TableCollection();
            TableDefinition actual = target[""];
            actual = target[null];
        }

        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void Should_Be_Able_Tools_Index_Table()
        {
            const string TABLE_NAME = "Table1";

            TableCollection target = new TableCollection();
            target.Add(TABLE_NAME);
            TableDefinition actual = target[0];

            Assert.AreEqual(TABLE_NAME, actual.TableName);
        }

        /// <summary>
        ///A test for Contains
        ///</summary>
        [TestMethod()]
        public void Should_Contain_Tables()
        {
            const string TABLE_NAME = "Table1";

            TableCollection target = new TableCollection();
            target.Add(TABLE_NAME);

            Assert.AreEqual(true, target.Contains(TABLE_NAME));
            Assert.AreEqual(false, target.Contains("Table That does not exist"));
            Assert.AreEqual(false, target.Contains(""));
            Assert.AreEqual(false, target.Contains(null));
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void Should_Be_Able_To_Add_Table()
        {
            const string TABLE_NAME = "Table1";

            TableCollection target = new TableCollection(); 
            TableDefinition actual = target.Add(TABLE_NAME);
            
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(TABLE_NAME, actual.TableName);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Should_Not_Be_Able_To_Add_Table_With_Empty_Name()
        {
            TableCollection target = new TableCollection();
            target.Add("");
            target.Add(null);
        }

        [TestMethod]
        public void Should_Clear_Tables()
        {
            TableCollection target = new TableCollection();
            target.Add("testTable");
            target.Clear();

            Assert.AreEqual(0, target.Count);
        }
    }
}
